package cn.com.panda.utils;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Trace;
import android.text.TextUtils;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class PermissionUtil {
    private Context mContext;

    public PermissionUtil(Context context){
        this.mContext = context;
    }

    public boolean isAllowPermission(String permission){
        boolean result = false;
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            if(!TextUtils.isEmpty(permission)){
                if (ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_GRANTED){
                    result = true;
                }
            }
        }else{
            result = true;
        }
        return result;
    }

    public void requestPermission(AppCompatActivity mActivity, String permission){
        String[] permissions = new String[]{permission};
        ActivityCompat.requestPermissions(mActivity, permissions, 0);
    }
}
